//
//  ContentView.swift
//  WorldLandmark
//
//  Created by liy on 2025/1/22.
//

import SwiftUI

struct ContentView: View {
  var body: some View {
    NavigationView {
			//List ForEach等要求被循环的每个元素都有一个唯一标识符（统称： 索引）
			//这样数据变更时可以迅速定位并进行UI刷新，提高性能
			//两种方法：
			//1.ArrayData.identified(by: \.id) id需为每个元素的唯一标识符属性 \.self
			//2.数组中元素遵循identifiable (需实现id属性)
      List(landmarks) { landmark in
				LankmarkCell(landmark: landmark)
      }
			.listStyle(.plain)
			.navigationTitle("世界地标")
    }
//    		.edgesIgnoringSafeArea(.all)
  }
}

#Preview {
  ContentView()
}

struct LankmarkCell: View {
	let landmark: Landmark
	var body: some View {
		NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
			Image(landmark.imageName)
				.resizable()
				.frame(width: 50, height: 50)
				.clipShape(RoundedRectangle(cornerRadius: 10))
			
			VStack(alignment: .leading) {
				Text(landmark.name)
				Text(landmark.location)
					.font(.subheadline)
					.foregroundStyle(.secondary)
			}
		}
	}
}
